package com.ghy.controller;



import com.ghy.dto.BannerInsertDTO;
import com.ghy.dto.BannerPageDTO;
import com.ghy.dto.BannerUpdateDTO;
import com.ghy.entity.Notice;
import com.ghy.result.Result;
import com.ghy.vo.BannerSimpleListVO;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.ghy.entity.Banner;
import com.ghy.service.BannerService;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.ghy.entity.Banner;
import com.ghy.service.BannerService;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 横幅表 控制层。
 *
 * @author ghy
 * @since 2024-12-22
 */
@Tag(name = "横幅")
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @Operation(summary ="新增——单条",description ="新增一条横幅记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody BannerInsertDTO dto) {
        return bannerService.insert(dto);
    }

    @Operation(summary ="查询——前n条",description ="按主键查询一条横幅记录")
    @GetMapping("top/{n}")
    public List<Banner> top (@PathVariable Long n) {
        return bannerService.top(n);
    }

    @Operation(summary ="查询——单条",description ="按主键查询一条横幅记录")
    @GetMapping("select/{id}")
    public Banner select(@PathVariable("id") Long id) {
        return bannerService.select(id);
    }

    @Operation(summary = "查询——简单查询全部", description = "查询全部横幅记录")

    @GetMapping("simpleList")
    public List<BannerSimpleListVO> simpleList() {
        return bannerService.simpleList();
    }


    @Operation(summary ="查询——分页",description ="分页查询横幅记录")
    @GetMapping("page")
    public Page<Banner> page(@Validated BannerPageDTO dto) {
        return bannerService.page(dto);
    }

    @Operation(summary="修改——单条",description="按主键修改一条横幅记录")
    @PutMapping("update")
    public boolean update(@RequestBody BannerUpdateDTO dto) {
        return bannerService.update(dto);
    }

    @Operation(summary ="删除——单条",description ="按主键删除一条横幅记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return bannerService.delete(id);
    }

    @Operation(summary="删除——批量",description ="按主键批量删除横幅记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return bannerService.deleteBatch(ids);
    }

    @Operation(summary = "修改——横幅图片", description = "选图片")
    @PostMapping("uploadBanner/{id}")
    public Result<String> uploadBanner(@RequestParam("bannerFile") MultipartFile bannerFile, @PathVariable("id") Long id){

        return new Result<>(bannerService.uploadBanner(bannerFile,id));
    }


}
